<template>
	<view class="hotActivity">
		<view class="search flex alignCenter">
			<input class="font14" type="text" placeholder="活动名称" v-model.trim="name" placeholder-class="font14 color666" maxlength="10" @confirm="searchClick">
			<text class="font14 bold" @click="searchClick">搜索</text>
		</view>
		<scroll-view class="scrollView" scroll-x="true" :scroll-with-animation="true" enable-flex="true" :scroll-into-view="`sub${scrollId}`" @scroll="scroll">
			<view :class="scrollId==index?'scrollItem font14 bold activeScroll':'scrollItem font14'" :id="`sub${index}`" v-for="(item,index) in subCategory" :key="index" @click.stop="clickScrollItem(item,index)">({{item.subjectCode}}){{item.title}}</view>
		</scroll-view>
		<view class="activityList flex justConBetween">
			<view class="leftBox">
				<template v-for="(item,index) in activityData">
					<view class="actOne" :key="index" v-if="index%2==0">
						<uni-activity :activityItem="item" :canStar="true" :canJoin="true" :key="index" @actComOper="actComOper"></uni-activity>
					</view>
				</template>
			</view>
			<view class="rightBox">
				<template v-for="(item,index) in activityData">
					<view class="actOne" :key="index" v-if="index%2!=0">
						<uni-activity :activityItem="item" :canStar="true" :canJoin="true" :key="index" @actComOper="actComOper"></uni-activity>
					</view>
				</template>
			</view>
		</view>
		<uni-nodata v-if="(activityData.length==0)"></uni-nodata>
	</view>
</template>

<script>
	import { getSubjectCategory } from "@/api/index.js"
	import { activityList } from "@/api/school.js"
	// import { joinActivity } from "@/api/send.js"
	export default {
		data() {
			return {
				name:'',
				scrollId:'0',
				subCategory:[],
				activityData:[],
				chooseSubject:'',
				page:1,
				pageSize:10,
				pageTotal:0,
			};
		},
		onLoad() {
			
		},
		onShow() {
			this.initPage()
			this.getCategory()
		},
		methods:{
			initPage(){
				this.page=1;
				this.activityData=[];
			},
			searchClick(){
				this.initPage();
				this.getList();
			},
			// 获取分区
			getCategory(){
				let param={"pageNum":1,"pageSize":100,"type":0,"year":new Date().getFullYear()}
				getSubjectCategory(param).then((res)=>{
					if(res.code==100000){
						this.subCategory=res.data.rows
						this.chooseSubject=res.data.rows[0]
						console.log('res',res)
						this.getList()
					}
				})
			},
			// 获取列表
			getList(){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				let param={
					page:this.page,
					size:this.pageSize,
					name:this.name,
					subjectCode:this.chooseSubject.subjectCode,
				}
				activityList(param).then((res)=>{
					uni.hideLoading()
					if(res.code==100000){
						this.activityData=this.activityData.concat(res.data.rows)
						this.pageTotal=Math.ceil(res.data.total/this.pageSize)
					}
				}).catch((err)=>{uni.hideLoading()})
			},
			// 活动的操作
			actComOper(obj){
				if(obj.type=='join'){
					this.initPage()
					this.getList()
				}
			},
			scroll(e){
				// console.log('scroll',e)
			},
			
			clickScrollItem(item,idx){
				this.chooseSubject=item
				this.scrollId=idx
				this.initPage()
				this.getList()
			}
		},
		onReachBottom() {
			if(this.page<this.pageTotal){
				++this.page
				this.getList()
			}else{
				uni.showToast({
					title:'我也是有底线的',
					icon:'none'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.search{
	padding: 30rpx 30rpx 0;
	box-sizing: border-box;
	background: #fff;
	input{
		border:1px solid $bordercolor;
		border-radius: 30rpx;
		height: 70rpx;
		line-height: 70rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		flex:1;
		margin:0 20rpx 0 0;
	}
}
.scrollView{
	white-space: nowrap;
	width: 100%;
	padding: 0 30rpx;
	box-sizing: border-box;
}
.scrollItem{
	display: inline-block;
	height: 80rpx;
	line-height: 80rpx;
	padding: 0 15rpx;
	margin: 0 15rpx;
	text-align: center;
	position:relative;
}
.activeScroll::after{
	content: '';
	display:block;
	position:absolute;
	height: 8rpx;
	width: 100%;
	left:0;
	bottom: 0;
	background:$colorMain;
	border-radius: 20rpx;
	box-shadow: 0 6rpx 10rpx rgba(0, 0, 0, .15);
}
.activityList{
	flex-wrap: wrap;
	padding: 30rpx;
	box-sizing: border-box;
	&>view{
		flex: 0 0 48%;
	}
	.actOne{
		margin-bottom: 30rpx;
		border-radius:8rpx;
	}
}
scroll-view ::-webkit-scrollbar {
	width: 0;
	height: 0;
	background-color: transparent;
}
</style>
